# !/usr/bin/env python
# -*-coding:utf-8 -*-
"""
@Author : Ayao
@Time   : 2022/5/25
@File   : 猜数字大小.py
"""

# The guess API is already defined for you.
# @param num, your guess
# @return -1 if my number is lower, 1 if my number is higher, otherwise return 0
# def guess(num: int) -> int:

"""
你可以通过调用一个预先定义好的接口 int guess(int num) 来获取猜测结果，返回值一共有 3 种可能的情况（-1，1 或 0）：

-1：我选出的数字比你猜的数字小 pick < num
1：我选出的数字比你猜的数字大 pick > num
0：我选出的数字和你猜的数字一样。恭喜！你猜对了！pick == num

链接：https://leetcode.cn/leetbook/read/binary-search/xee4ev/


"""


def guess(num: int) -> int:
    if 7 < num: return -1
    if 7 > num: return 1
    if 7 == num: return 0


class Solution:
    def guessNumber(self, n: int) -> int:
        left, right = 1, n
        while left <= right:
            mid = left + (right - left) // 2
            gue = guess(mid)
            if gue == -1:
                right = mid - 1
            elif gue == 1:
                left = mid + 1
            else:
                return mid


print(Solution().guessNumber(10))
